package com.company.project.search.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.company.project.common.utils.MD5Util;
import com.company.project.search.engine.Engine;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;

import java.util.Date;

@Data
@TableName("search")
@Document(indexName = "namesearchs", type = "search", indexStoreType = "fs", shards = 5, replicas = 1, refreshInterval = "-1")
@Setting(settingPath = "setting/elasticsearchSetting.json")
public class Search {

    public Search() {

    }

    public static Search newInstance(@Engine int _engine) {
        Search search = new Search();
        search.engine = _engine;
        search.createTime = new Date();
        return search;
    }

    @Id
    private String id;

    @Engine
    @Field(type = FieldType.Long)
    private int engine;
    @Field(type = FieldType.Text)
    private String name;
    @Field(type = FieldType.Text)
    private String author;
    @Field(type = FieldType.Text)
    private String url;
    @Field(type = FieldType.Text)
    private String source;
    @Field(type = FieldType.Text)
    private String category;
    @Field(type = FieldType.Text)
    private String book;
    @Field(type = FieldType.Long)
    private int total;
    @Field(type = FieldType.Text)
    private String token;

    @Field(type = FieldType.Text)
    private String publishDate;
    @Field(type = FieldType.Text)
    private String param;
    @Field(type = FieldType.Text)
    private String page;

    private Date createTime;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        this.id = engine + "@" + (MD5Util.MD5(name == null ? "null" : name));
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    @Override
    public String toString() {
        return "Search{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", url='" + url + '\'' +
                ", source='" + source + '\'' +
                ", category='" + category + '\'' +
                ", total=" + total +
                ", token='" + token + '\'' +
                ", publishDate=" + publishDate +
                ", param='" + param + '\'' +
                ", page='" + page + '\'' +
                '}';
    }
}
